package com.itheima.jwt;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;


import java.util.Date;

public class JwtTest {
    public static void main(String[] args) {

        //获取当前时间
        long currentTimeMillis = System.currentTimeMillis();
        //再转换成date数据
        Date date = new Date(currentTimeMillis);

        JwtBuilder jwtBuilder = Jwts.builder()
                .setId("66")
                .setSubject("黑马程序员")
                .setIssuedAt(new Date())
               // .setExpiration(date)//设置过期时间
                //添加自定义数据
                .claim("name","zhaoqing")
                .claim("user","itheima")
                .signWith(SignatureAlgorithm.HS256,"itheima");
        //生成jwt
        String compact = jwtBuilder.compact();
        System.out.println(compact);
        //解析jwt
        Claims itheima = Jwts.parser().setSigningKey("itheima").parseClaimsJws(compact).getBody();
        System.out.println(itheima);
    }
}
